package Day05_在圆内随机生成点;

import java.util.Random;

/**
 * --------------------------------------------------------------------------------
 * 题目：
 *      给定圆的半径和圆心的位置，实现函数 randPoint ，在圆中产生均匀随机点。
 *      实现Solution类:
 *          Solution(double radius, double x_center, double y_center)用圆的半径
 *              radius和圆心的位置 (x_center, y_center) 初始化对象
 *          randPoint() 返回圆内的一个随机点。圆周上的一点被认为在圆内。
 *              答案作为数组返回 [x, y] 。
 * --------------------------------------------------------------------------------
 * 示例：
 *      输入:
 *          ["Solution","randPoint","randPoint","randPoint"]
 *          [[1.0, 0.0, 0.0], [], [], []]
 *      输出: [null, [-0.02493, -0.38077], [0.82314, 0.38945], [0.36572, 0.17248]]
 *      解释:
 *          Solution solution = new Solution(1.0, 0.0, 0.0);
 *          solution.randPoint ();//返回[-0.02493，-0.38077]
 *          solution.randPoint ();//返回[0.82314,0.38945]
 *          solution.randPoint ();//返回[0.36572,0.17248]
 * --------------------------------------------------------------------------------
 * 方法：
 *      数学法
 * --------------------------------------------------------------------------------
 */
class Solution {
    Random random;
    double xc, yc, r;

    Solution(double radius, double x_center, double y_center) {
        random = new Random();
        xc = x_center;
        yc = y_center;
        r = radius;
    }

    public static void main(String[] args) {
        System.out.println(1);
    }
    public double[] randPoint() {
        double u = random.nextDouble();
        double theta = random.nextDouble() * 2 * Math.PI;
        double r = Math.sqrt(u);
        return new double[]{xc + r * Math.cos(theta) * this.r, yc + r * Math.sin(theta) * this.r};
    }
}